{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tutorial about example datasets" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "import sys\n", "from pathlib import Path\n", "import shutil\n", "import logging\n", "\n", "import httpx\n", "\n", "import locan as lc" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "lc.show_versions(system=False, dependencies=False, verbose=False)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "logging.basicConfig(stream=sys.stdout, level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')\n", "logger = logging.getLogger()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load SMLM data from ShareLoc.XYZ" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "SMLM data can e.g. be found on [ShareLoc.XYZ](https://shareloc.xyz), an open platform for sharing single-molecule localization microscopy data.\n", "\n", "Copy a specific download link for downloading a smlm-file." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = \"https://zenodo.org/records/7182242/files/UniWue_Tubulin_AF647_3/data.smlm\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "response = httpx.get(url)\n", "print(\"Response is ok: \", response.status_code == httpx.codes.ok)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "file_path = Path.home() / Path(url).name\n", "\n", "with open(file_path, 'wb') as file:\n", " for chunk in response.iter_bytes(chunk_size=128):\n", " file.write(chunk)\n", " \n", "file_path" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Load data and visualize" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "locdata = lc.load_SMLM_file(file_path)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print information about the data: " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "print('Data head:')\n", "print(locdata.data.head(), '\\n')\n", "print('Summary:')\n", "locdata.print_summary()\n", "print('Properties:')\n", "print(locdata.properties)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "lc.render_2d(locdata, bin_size=100, rescale=lc.Trafo.EQUALIZE_0P3);" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "lc.render_2d(locdata, bin_size=10, rescale=lc.Trafo.EQUALIZE_0P3,\n", " bin_range=((15_000, 20_200), (10_000, 15_000)));" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load SMLM data from LocanDatasets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Selected example datasets are provided in a separate directory (repository) called `LocanDatasets`.\n", "\n", "These datasets can be loaded by ready-to-go utility functions." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Set up a datasets directory" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lc.DATASETS_DIR = Path.home() / 'LocanDatasets'\n", "lc.DATASETS_DIR.mkdir(exist_ok=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Load dSTORM data of nuclear pore complexes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is a rather large 2D dataset with > 2 mio localizations." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = \"https://raw.githubusercontent.com/super-resolution/LocanDatasets/main/smlm_data/npc_gp210.asdf\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "response = httpx.get(url)\n", "print(\"Response is ok: \", response.status_code == httpx.codes.ok)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "response.status_code" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "file_path = lc.DATASETS_DIR / 'npc_gp210.asdf'\n", "\n", "with open(file_path, 'wb') as file:\n", " for chunk in response.iter_bytes(chunk_size=128):\n", " file.write(chunk)\n", " \n", "file_path" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "dat = lc.load_npc()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print information about the data: " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "print('Data head:')\n", "print(dat.data.head(), '\\n')\n", "print('Summary:')\n", "dat.print_summary()\n", "print('Properties:')\n", "print(dat.properties)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "lc.render_2d(dat, bin_size=100, rescale=lc.Trafo.EQUALIZE_0P3);" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "lc.render_2d(dat, bin_size=10, rescale=lc.Trafo.EQUALIZE_0P3,\n", " bin_range=((0, 5000), (0, 5000)));" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "### Load dSTORM data of microtubules" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is a rather large 2D dataset with about 1.5 mio localizations." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = \"https://raw.githubusercontent.com/super-resolution/LocanDatasets/main/smlm_data/tubulin_cos7.asdf\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "response = httpx.get(url)\n", "print(\"Response is ok: \", response.status_code == httpx.codes.ok)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "file_path = lc.DATASETS_DIR / 'tubulin_cos7.asdf'\n", "\n", "with open(file_path, 'wb') as file:\n", " for chunk in response.iter_bytes(chunk_size=128):\n", " file.write(chunk)\n", " \n", "file_path" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "dat = lc.load_tubulin()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print information about the data: " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "print('Data head:')\n", "print(dat.data.head(), '\\n')\n", "print('Summary:')\n", "dat.print_summary()\n", "print('Properties:')\n", "print(dat.properties)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "lc.render_2d(dat, bin_size=100, rescale=lc.Trafo.EQUALIZE_0P3);" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "lc.render_2d(dat, bin_size=10, rescale=lc.Trafo.EQUALIZE_0P3,\n", " bin_range=((0, 4000), (6000, 10_000)));" ] } ], "metadata": { "execution": { "timeout": 360 }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.6" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }